/*
 * Copyright 2012 Marsrutai.lt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.model;

import lt.marsrutai.mobile.android.dao.Identifier;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * Bookmark representing a location where multiple types of transports stop.
 * 
 * @author Justas
 */
public class StopBookmark extends Bookmark implements Parcelable {

    public static final Parcelable.Creator<StopBookmark> CREATOR = new Parcelable.Creator<StopBookmark>() {

        @Override
        public StopBookmark createFromParcel(Parcel source) {
            return new StopBookmark(source);
        }

        @Override
        public StopBookmark[] newArray(int size) {
            return new StopBookmark[size];
        }
    };

    private String stopId;
    private String stopName;
    private String stopDirectionName;

    public StopBookmark() {
    }

    public StopBookmark(Parcel in) {
        super(in);

        stopId = in.readString();
        stopName = in.readString();
        stopDirectionName = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        super.writeToParcel(dest, flags);

        dest.writeString(stopId);
        dest.writeString(stopName);
        dest.writeString(stopDirectionName);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Identifier
    public String getStopId() {
        return stopId;
    }

    public void setStopId(String stopId) {
        this.stopId = stopId;
    }

    @Identifier
    public String getStopName() {
        return stopName;
    }

    public void setStopName(String stopName) {
        this.stopName = stopName;
    }

    @Identifier
    public String getStopDirectionName() {
        return stopDirectionName;
    }

    public void setStopDirectionName(String stopDirectionName) {
        this.stopDirectionName = stopDirectionName;
    }

    @Override
    public String toString() {
        return String.format("StopBookmark [scope=%s, stopId=%s]", getScopeFolder(), stopId);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((stopDirectionName == null) ? 0 : stopDirectionName.hashCode());
        result = prime * result + ((stopId == null) ? 0 : stopId.hashCode());
        result = prime * result + ((stopName == null) ? 0 : stopName.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!super.equals(obj)) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        StopBookmark other = (StopBookmark) obj;
        if (stopDirectionName == null) {
            if (other.stopDirectionName != null) {
                return false;
            }
        }
        else if (!stopDirectionName.equals(other.stopDirectionName)) {
            return false;
        }
        if (stopId == null) {
            if (other.stopId != null) {
                return false;
            }
        }
        else if (!stopId.equals(other.stopId)) {
            return false;
        }
        if (stopName == null) {
            if (other.stopName != null) {
                return false;
            }
        }
        else if (!stopName.equals(other.stopName)) {
            return false;
        }
        return true;
    }

}
